﻿///检查是否是正的整数或者小数或0
function is_numeric1(obj)
{
    var reg;
    if (/^\d+(\.\d+)?$/.test(obj))
    {
        return true;
    }
    else
    {
        return false;
    }
}

function Add()
{
    var prefix = "ctl00_ContentPlaceHolder1_";
    var title = document.getElementById(prefix + "txtTitle");
    var costmoney = document.getElementById(prefix + "txtCostMoney");
    var blogmaxpvmoney = document.getElementById(prefix + "hidBlogMaxPVMoney");

    if (title.value.length == 0)
    {
        alert('请输入标题！');
        title.focus();
        return false;
    }
    if (costmoney.value.length == 0)
    {
        alert('请输入费用！');
        costmoney.focus();
        return false;
    }
    if (!is_numeric1(costmoney.value))
    {
        alert('费用格式不正确！');
        costmoney.focus();
        return false;
    }
    if (costmoney.value * 1 > blogmaxpvmoney*1)
    {
        alert('费用超过最大值');
        costmoney.focus();
        return false;
    }

    obj = document.getElementById(prefix + "rblBlogBigType");
    var rbls = obj.getElementsByTagName('input');
    var j = 0;
    for (var i = 0; i < rbls.length; i++)
    {
        if (rbls[i].type == 'radio')
        {
            if (rbls[2].checked)//mp3
            {
                j++;
            }
        }
    }

    if (j == 0)
    {
        var oEditor = FCKeditorAPI.GetInstance(prefix + "txtContent");
        var content = oEditor.GetXHTML(true);
        content = content.replace(/　/g, "");
        content = content.replace(/\s/g, "");
        content = content.replace(/&nbsp;/g, "");
        content = content.replace(/<br\/>/g, "");
        content = content.replace(/<p><\/p>/g, "");
        content = content.replace(/<div><\/div>/g, "");
        if (content == null || content == "")
        {
            oEditor.SetHTML("");
            alert('请输入内容！');
            return false;
        }
    }
    else//判断是否上传文件
    {
        var file = document.getElementById(prefix + "fuFile");
        if (file.value.length == 0)
        {
            alert('请上传mp3文件');
            file.focus();
            return false;
        }
    }

    return true;
}

function Edit()
{
    var prefix = "ctl00_ContentPlaceHolder1_";
    var title = document.getElementById(prefix + "txtTitle");

    if (title.value.length == 0)
    {
        alert('请输入标题！');
        title.focus();
        return false;
    }

    var oEditor = FCKeditorAPI.GetInstance(prefix + "txtContent");
    var content = oEditor.GetXHTML(true);
    content = content.replace(/　/g, "");
    content = content.replace(/\s/g, "");
    content = content.replace(/&nbsp;/g, "");
    content = content.replace(/<br\/>/g, "");
    content = content.replace(/<p><\/p>/g, "");
    content = content.replace(/<div><\/div>/g, "");
    if (content == null || content == "")
    {
        oEditor.SetHTML("");
        alert('请输入内容！');
        return false;
    }

    return true;
}

function ReplyAdd()
{
    var prefix = "ctl00_ContentPlaceHolder1_";
    var replycontent = document.getElementById(prefix + "txtReply");
    if (replycontent.value.length == 0)
    {
        alert("评论内容不能为空！");
        replycontent.focus();
        return false;
    }
    return true;
}

function Recommand()
{
    var prefix = "ctl00_ContentPlaceHolder1_";
    var blogid = document.getElementById(prefix + "hidID").value;
    var objecttype = 1;
    var lblrecommandcount = document.getElementById(prefix + "lblRecommandCount");
    $.ajax({
        type: "GET",
        url: '../ajax/RecommandClick.aspx',
        data: ({ objectid: blogid, objecttype: objecttype, code: Math.random() }),
        dataType: 'html',
        success: function (data)
        {
            if (data == '请先登录')
            {
                alert("请先登录");
                return false;
            }
            else if (data == '已经推荐过')
            {
                alert("已经推荐过");
                return false;
            }
            else
            {
                lblrecommandcount.innerText = data;
                return false;
            }
        }
    });
}

function Favorite(objectid,objecttype)
{
//    var prefix = "ctl00_ContentPlaceHolder1_";
//    var blogid = document.getElementById(prefix + "hidID").value;
//    var objecttype = 1;
//    var lblrecommandcount = document.getElementById(prefix + "lblRecommandCount");
    $.ajax({
        type: "GET",
        url: '../ajax/FavoriteClick.aspx',
        data: ({ objectid: objectid, objecttype: objecttype, code: Math.random() }),
        dataType: 'html',
        success: function (data)
        {
            if (data == '请先登录')
            {
                alert("请先登录");
                return false;
            }
            else
            {
                alert(data);
                return false;
            }
        }
    });
}

//首页推荐
function dig(blogid)
{
    var digcount =document.getElementById('digg_count_' + blogid);
    var objecttype = 1;
    $.ajax({
        type: "GET",
        url: '../ajax/RecommandClick.aspx',
        data: ({ objectid: blogid, objecttype: objecttype, code: Math.random() }),
        dataType: 'html',
        success: function (data)
        {
            if (data == '请先登录')
            {
                alert("请先登录");
                return false;
            }
            else if (data == '已经推荐过')
            {
                alert("已经推荐过");
                return false;
            }
            else
            {
                digcount.innerText = data;
                return false;
            }
        }
    });
}

function loginsmall()
{
    var rand = Math.random();
    var vv = showModalDialog('../UserSetting/LoginSmall.aspx?&rand=' + rand, window, 'dialogWidth:580px; dialogHeight:350px;help:0;status:0;resizeable:0;');
    if (vv == 'succ')//登录成功
    {
        window.location.href = document.URL
    }
}

function sendmessage(touserid)
{
    var prefix = "ctl00_ContentPlaceHolder1_";
    var currentuserid = document.getElementById(prefix + "hidCurrentUserID").value;
    var rand = Math.random();
    if (currentuserid == '0')//没有登录
    {
        var vv = showModalDialog('../UserSetting/LoginSmall.aspx?&rand=' + rand, window, 'dialogWidth:580px; dialogHeight:350px;help:0;status:0;resizeable:0;');
        if (vv == 'succ')//登录成功
        {
            window.location.href = document.URL
        }
    }
    else//已经登录
    {
        showModalDialog('../UserSetting/SendMessage.aspx?touserid=' + touserid + '&rand=' + rand, window, 'dialogWidth:580px; dialogHeight:350px;help:0;status:0;resizeable:0;');
    }
}


function setTab(name, cursel, n)
{
    for (i = 1; i <= n; i++)
    {
        var menu = document.getElementById(name + i);
        var con = document.getElementById("con_" + name + "_" + i);
        //menu.className = i == cursel ? "style=\"color:Red\"" : "";
        menu.style.color = i == cursel ? "Red" : "black";
        con.style.display = i == cursel ? "block" : "none";
    }
}

function Reply(nickname,userid)
{

    var txtReply = document.getElementById("ctl00_ContentPlaceHolder1_txtReply");
    txtReply.focus();
    txtReply.value = "回复" + nickname + ":";

    var hidUserID = document.getElementById("ctl00_ContentPlaceHolder1_hidToUserID");
    hidUserID.value = userid;
    //alert(nickname);
}